<%@ page language="java" import="java.util.*,com.king.cms.common.*, com.king.cms.orm.CmsUser" pageEncoding="UTF-8"%>
<jsp:directive.page import="com.king.cms.db.DBOperator"/>
<%@ include file="/hotel/include/css.jsp"%><%-- /*包含css样式表*/ --%> 
<%
String flag = request.getParameter("save");
if(flag != null){
  String newpass = request.getParameter("newpass"); 
  String oldpass = request.getParameter("oldpassword");
  CmsUser obj = (CmsUser)request.getSession().getAttribute(ParameterDic.ECPMUSERSESSION);
  if(obj != null){
     Integer userId = obj.getId();  
     String oldpassword = oldpass;
     String  pass = newpass;
     if(InitSystem.getBpmParam("isUseMd5") != null && "true".equals(InitSystem.getBpmParam("isUseMd5"))){
        oldpassword = MD5.md5(oldpass);
        pass = MD5.md5(newpass);
     }
     DBOperator dbo = new DBOperator(session.getServletContext());
     List list = dbo.select("select * from cms_user where user_pass=? and ID=?",new Object[]{oldpassword,userId});
    
     if(list.size() == 1){
	     dbo.update("update cms_user set user_pass=? where ID=?",new Object[]{pass,userId});
	     out.print("<script>");
	     out.print("alert('密码修改成功');");
	     out.print("window.close();");
	     out.print("</script>");
      }else{
         out.print("<script>");
	     out.print("alert('旧密码错误');");
	     out.print("window.location.href='modifypass.jsp'");
	      out.print("</script>");
      }
  }



}



 %>
<html>
<head>
<title>信息发布系统-修改密码</title>
<script>
function changepass(){
   var flag = true;
   if(clskg(form1.oldpassword.value) == ''){
       alert('旧密码不能为空或空格字符');
       
       flag = false;
       return;
   }
   if(clskg(form1.newpass.value) == ''){
       alert('新密码不能为空或空格字符');
       
       flag = false;
       return;
   }
   if(clskg(form1.confirmpass.value) == ''){
       alert('确认新密码不能为空或空格字符'); 
       flag = false;
       return;
   }
   if(clskg(form1.newpass.value)!= clskg(form1.confirmpass.value)){
       alert('两次输入密码不一致'); 
       flag = false;
       return;
   }
   form1.submit()


}
function clskg(va){
	  var th=/\s/g;
	  va=va.replace(th,'');
	 return va;
	}
</script>
<head>
</head>
<body>
<form name="form1"   method="post" action="modifypass.jsp"> 
<center>
<br>
<table border="0" cellpadding="4" cellspacing="1" style="border-collapse: collapse;" bordercolor="#111111" class="bg_table" width="80%"  align="center">
  <tr>
    <td class="top_td" colspan="2" align="center">修改密码</td>
  </tr>
   <tr class="td3" > 
    <td align="center" >旧密码：</td> 
    <td align="center" ><input type="password" class="area100" name="oldpassword" value=""></td>
  </tr> 
    <tr class="td3" > 
    <td align="center" >输入新密码：</td> 
    <td align="center" ><input type="hidden" class="area100" name="save" value="true"><input type="password" class="area100" name="newpass" value=""></td>
  </tr> 
  <tr class="td3" > 
    <td align="center" >确认新密码：</td> 
    <td align="center" ><input type="password" class="area100" name="confirmpass" value=""></td>
  </tr> 
  <tr class="td2" > 
    <td align="center" colspan="2"><input type="button" class="area100" onclick="changepass()" value="确定">&nbsp;<input type="button" class="area100" onclick="window.close();" value="取消"></td> 
   
  </tr>   
</table>
</center>
</form> 
</body>
</html>